# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=nvchecker
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.12
pkgrel=3
pkgdesc="New version checker for software releases (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'mingw32' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://github.com/lilydjwg/nvchecker"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-structlog"
         "${MINGW_PACKAGE_PREFIX}-python-platformdirs"
         "${MINGW_PACKAGE_PREFIX}-python-tornado"
         "${MINGW_PACKAGE_PREFIX}-python-pycurl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-docutils"
             "${MINGW_PACKAGE_PREFIX}-python-pygments"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-asyncio"
              "${MINGW_PACKAGE_PREFIX}-python-flaky"
              "${MINGW_PACKAGE_PREFIX}-python-lxml")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-lxml: for the htmlparser source"
            "${MINGW_PACKAGE_PREFIX}-python-packaging: for the pypi source"
            "${MINGW_PACKAGE_PREFIX}-python-gobject: for nvchecker-notify"
            "${MINGW_PACKAGE_PREFIX}-python-awesomeversion: for sorting versions"
            "${MINGW_PACKAGE_PREFIX}-libnotify: for nvchecker-notify"
            "git: support for git repositories")
options=(!strip)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('4200ddf733448c52309f110c6fa916727a7400f444855afa8ffe7ff1e5b0b6c8')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  "${MINGW_PREFIX}"/bin/python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE -t "$pkgdir"${MINGW_PREFIX}/share/licenses/$_realname

  for _f in ini2toml notify; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${pkgdir}${MINGW_PREFIX}/bin/nvchecker-${_f}"
  done
}
